<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>40.圆角边框渐变色的多种实现</title>
  </head>
  <link rel="stylesheet" href="../common.css" />
  <style>
    section {
      width: 460px;
    }
    div {
      cursor: pointer;
      position: relative;
      width: 180px;
      height: 60px;
      margin-bottom: 20px;
      margin-right: 20px;
      font-size: 15px;
      color: #e2fffd;
      transition: all 0.5s ease-in-out;
      position: relative;
    }
    div:hover {
      filter: brightness(1.3);
    }
    div:nth-child(1) {
      --bg: linear-gradient(180deg, #346575 0%, #1a283b 100%);
      --border: linear-gradient(270deg, #455364, #aec9e9, #455364);
      border: 1px solid transparent;
      /* var(--bg)背景色  var(--border)边框色 */
      background-image: var(--bg), var(--border);
      background-origin: border-box;
      background-clip: content-box, border-box;
      border-radius: 10px;
    }
    div:nth-child(2) {
      z-index: 1;
      width: 180px;
      height: 60px;
      border-radius: 10px;
      background: linear-gradient(270deg, #455364, #aec9e9, #455364);
    }
    div:nth-child(2)::after {
      content: "";
      position: absolute;
      /* 设置层级为-1，避免遮挡内容 */
      z-index: -1;
      width: calc(100% - 2px);
      height: calc(100% - 2px);
      background: linear-gradient(180deg, #27a6a7 0%, #054146 100%);
      left: 50%;
      top: 50%;
      transform: translate(-50%, -50%);
      border-radius: 10px;
    }
    div:nth-child(3),
    div:nth-child(4),
    div:nth-child(5),
    div:nth-child(6) {
      --border-radius: 10px;
      --border-width: 1px;
      --border-color: linear-gradient(
        270deg,
        rgba(69, 83, 100, 1),
        rgba(126, 145, 169, 1),
        rgba(69, 83, 100, 1)
      );
      width: 200px;
      height: 80px;
      position: relative;
      color: #fff;
      border-radius: var(--border-radius);
      background: rgba(38, 70, 93, 0.2);
      backdrop-filter: blur(10px);
    }
    div:nth-child(3)::after,
    div:nth-child(4)::after,
    div:nth-child(5)::after,
    div:nth-child(6)::after {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      padding: var(--border-width);
      border-radius: var(--border-radius);
      background: var(--border-color);
      /* 随便定义一个颜色 */
      --mask-bg: linear-gradient(red, red);
      /* 类似background-clip */
      --mask-clip: content-box, padding-box;
      /* mask允许使用者通过遮罩或者裁切特定区域的图片的方式来隐藏一个元素的部分或者全部可见区域 */
      /* mask-image类似background-image 设置了用作元素蒙版层的图像，默认值为none，值为透明图片，或透明渐变 */
      -webkit-mask-image: var(--mask-bg), var(--mask-bg);
      /* 默认值为border-box，可选值与background-origin相同 */
      -webkit-mask-clip: var(--mask-clip);
      /* exclude排除，只显示不重合的地方,Firefox支持4个属性 */
      mask-composite: exclude;
      /* 只显示下方遮罩，重合的地方不显示 */
      -webkit-mask-composite: destination-out;
    }
    div:nth-child(4) {
      --border-color: linear-gradient(
        180deg,
        rgba(44, 135, 124, 1),
        rgba(95, 250, 255, 1),
        rgba(63, 166, 156, 1)
      );
      background: transparent;
      box-shadow: -4px 2px 4px 0px rgba(0, 0, 0, 0.2),
        inset 0px 0px 12px 0px rgba(92, 242, 246, 0.61);
    }
    div:nth-child(5) {
      --border-width: 3px;
      --border-radius: 50%;
      --border-color: linear-gradient(180deg, #18f77f, #17ffff);
      background: transparent;
      width: 100px;
      height: 100px;
    }
    div:nth-child(6) {
      --border-width: 2px;
      --border-radius: 100px 0 0 100px;
      --border-color: linear-gradient(
        180deg,
        rgba(151, 151, 151, 0.3),
        rgba(131, 150, 162, 1),
        rgba(151, 151, 151, 0.3)
      );
      width: 180px;
      height: 100px;
      background: rgba(20, 97, 125, 0.06);
      box-shadow: 4px 2px 4px 0px rgba(0, 0, 0, 0.2);
      backdrop-filter: blur(4px);
    }

    div:nth-child(7) {
      width: 200px;
      height: 100px;
      border-radius: 10px;
      box-shadow: 4px 2px 4px 0px rgba(0, 0, 0, 0.2);
      overflow: hidden;
    }
    div:nth-child(7):after {
      content: "";
      position: absolute;
      width: 100%;
      height: 100%;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      border: 4px solid;
      border-image: linear-gradient(
          115deg,
          #4fcf70,
          #fad648,
          #a767e5,
          #12bcfe,
          #44ce7b
        )
        2 2;
    }
    div:nth-child(8) {
      width: 100px;
      height: 100px;
      border: 4px solid;
      border-image: linear-gradient(270deg, #18f77f, #17ffff) 1 1;
      clip-path: inset(0 round 10px);
    }
  </style>

  <body>
    <section class="flex-wrap">
      <!-- 方法一：background-clip ：content-box, border-box，背景无法透明
      background-clip 设置元素的背景（背景图片或颜色）是否延伸到边框下面，部分取值和 box-sizing 类似
      background-clip: border-box 表示设置的背景 background-image 将延伸至边框
      background-clip: content-box 表示设置的背景 background-image 被裁剪至内容区（content box）外沿
      要 background-origin: border-box 使图案完整显示
    -->
      <div class="flex-column j_c">background-clip</div>
      <!-- 方法二：伪元素叠加，背景无法透明 -->
      <div class="flex-column j_c">伪元素</div>
      <!-- 方法三 :mask遮罩 背景色带透明 -->
      <div class="flex-column j_c">mask</div>
      <!-- mask遮罩 背景透明 -->
      <div class="flex-column j_c">背景透明</div>
      <!-- mask遮罩 背景透明 -->
      <div class="flex-column j_c">透明圆角</div>
      <div class="flex-column j_c">半圆</div>
      <!-- 方法四： border-image + overflow: hidden 边框内不是圆角 -->
      <div class="flex-column j_c">border-image + overflow</div>
      <!-- 方法五：clip-path  边框内不是圆角-->
      <div class="flex-column j_c">clip-path</div>
    </section>
  </body>
</html>
